<template>
	<view class="business-district">
		<view class="header">
			<view class="navbar">
				<view class="navbar-fixed">
					<view :style="{ height: statusBarHeight + 'px' }"></view>
					<view class="navbar-content" :style="{ height: navBarHeight + 'px', width: windowWidth + 'px' }">
						<!-- <image src="../../static/image/back.png" @click="back()"></image> -->
						<view class="navbar-search">商圈</view>
					</view>
				</view>
				<view :style="{ height: statusBarHeight + navBarHeight + 'px' }"></view>
			</view>
			<view class="searchbox">
				<view class="search">
					<view class="scan">
						<image src="../../static/ss1.png"></image>
					</view>
					<view class="inputbox">
						<input v-model="keyword" placeholder="搜索店铺" />
					</view>

					<view class="searchbut" @click="tosearch()">搜索</view>
				</view>
			</view>
		</view>
		<view style="height: 320rpx;"></view>
		<view class="content">
			<scroll-view class="cate" scroll-y>
				<view @click="setFloort(index,item)" class="cate-item" 
				:class="[floor == item.id?'cate-item-select':'']" 
				v-for="(item, index) in tiptypelist" :key="index">
					{{ item.name }}
				</view>
			</scroll-view>
			<scroll-view scroll-y @scrolltolower="getlist" :lower-threshold="100">
				<kong v-if="list.length==0 && isEnd && !loading"></kong>
				<view class="list">
					<view @click="tostoredetail(item)" class="list-item" v-for="item in list" >
						<u-image radius="20rpx" :showLoading="true" mode="aspectFill" height="140rpx" width="140rpx"
							class="image" :src="item.logo"></u-image>
						<view class="item-content">
							<view>{{ item.merch_name }}</view>
							<view class="discount_percent" v-if="(item.discount_rate)<1">{{parseFloat(item.discount_rate*10).toFixed(1)}}折</view>
							<!-- <view class="discount_percent" v-if="(item.discount_rate*10)<1">{{item.discount_rate*10}}折</view> -->
							<!-- <view v-if="item.floor && item.house_num">{{ item.floor }}/{{ item.house_num }}</view> -->
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- <view class="catebox">
			<view class="titbox">
				<view class="cateitem" v-for="(item,index) in catelist" :key="index"
					:style="{'color':index==cateindex?'#F94D29':''}" @click="changecate(index)">
					<view>{{item.title}}</view>
					<image v-if="index==cateindex" :src="item.iconed"></image>
					<image v-else :src="item.icon"></image>
				</view>
			</view>
		</view>
		<view style="height: 98rpx;"></view>
		<view class="listbox">
			<view class="listitem" v-for="(item,index) in list" :key="index" @click="tostoredetail(item)">
				<view class="store">
					<view class="storeimg">
						<image :src="(item.merch_picarr.split(',')).splice(1,2)"></image>
					</view>
					<view class="logobox">
						<image :src="item.logo"></image>
					</view>
					<view style="height: 60rpx;"></view>
					<view class="address">{{item.floor}}/{{item.house_num}}</view>
					<view class="storename">{{item.merch_name}}</view>
				</view>
				<image class="newstore" src="../../static/xd.png"></image>
			</view>
		</view>
		
		<uni-popup ref="popup" type="top" background-color="#fff">
			<view class="tiptype">
				<view class="boxitem"   v-if="cateindex==0">
					<view class="itembox" v-for="(item,index) in tiptypelist" :key="index" @click="changebx(item,index)"
						:style="{'color':index==cate_id?'#F94D29':'','border':index==cate_id?'2rpx solid #F94D29':''}">
						{{item.name}}
					</view>
				</view>
				<view class="boxitem" v-else>
					<view  class="itembox" v-for="(item,index) in floorlist" :key="index" @click="changefloor(item,index)"
						:style="{'color':index==floor?'#F94D29':'','border':index==floor?'2rpx solid #F94D29':''}">
						{{item}}
					</view>
				</view>
			</view>
		</uni-popup> -->
	</view>
</template>

<script>
import kong from '../../components/kong.vue'
export default {
	components: {
		kong
	},
	data() {
		return {
			statusBarHeight: 20,
			/* 状态栏高度 */
			navBarHeight: 45,
			/* 导航栏高度 */
			windowWidth: 375,
			/* 窗口宽度 */
			/* 设定状态栏默认高度 */
			catelist: [{
				title: '分类',
				icon: '../../static/xia1.png',
				iconed: '../../static/up.png'
			},
			{
				title: '楼层',
				icon: '../../static/xia1.png',
				iconed: '../../static/up.png'
			}
			],
			cateindex: null, //筛选索引
			tiptypelist: [],//分类列表
			cate_id: null,
			top: true,
			page_index: 1,
			list: [],
			floorlist: [],//楼层列表
			floor: 0,
			is_data: true,
			loading: false,
			isEnd: false,
			keyword:'',
		}
	},
	onShow() {
		this.is_data= true
		this.isEnd= false
		this.page_index =1
		this.loading = false
		this.list = []
		this.floor = 0
		this.getnav()
		this.getlist()
		this.getfloorlist()
		this.getcate()
	},
	onReachBottom() {
		this.is_data && this.getlist()
	},
	methods: {
		setFloort(index,item) {
			this.loading = false
			this.isEnd = false
			this.is_data = true
			this.page_index = 1
			this.list = []
			this.floor = item.id
			this.getlist()
		},
		getnav() {
			// 获取手机系统信息
			const info = uni.getSystemInfoSync()
			// 设置状态栏高度（H5顶部无状态栏小程序有状态栏需要撑起高度）
			this.statusBarHeight = info.statusBarHeight
			this.windowWidth = info.windowWidth
			// 除了h5 app mp-alipay的情况下执行
			// #ifndef H5 || APP-PLUS || MP-ALIPAY
			// 获取胶囊的位置
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			console.log(menuButtonInfo);
			// (胶囊底部高度 - 状态栏的高度) + (胶囊顶部高度 - 状态栏内的高度) = 导航栏的高度
			this.navBarHeight = (menuButtonInfo.bottom - info.statusBarHeight) + (menuButtonInfo.top - info
				.statusBarHeight)
			this.windowWidth = menuButtonInfo.left
			// #endif
		},
		//搜索
		tosearch() {
			this.is_data= true
			this.isEnd= false
			this.page_index =1
			this.loading = false
			this.list = []
			this.floor = 0
			this.getlist()
			// uni.navigateTo({
			// 	url: '/personalData/search/search'
			// })
		},
		changecate(index) {
			if (this.cateindex == index) {
				this.cateindex = null
				this.$refs.popup.close()
			} else {
				this.cateindex = index
				this.$refs.popup.open('top')
			}
		},
		//类型选择
		changebx(item, index) {
			this.is_data = true
			this.page_index = 1
			this.list = []
			this.cate_id = index
			setTimeout(() => {
				this.$refs.popup.close()
				this.getlist()
			}, 10)
		},
		//楼层选择
		changefloor(item, index) {
			this.is_data = true
			this.page_index = 1
			this.list = []
			this.floor = index
			setTimeout(() => {
				this.$refs.popup.close()
				this.getlist()
			}, 10)
		},
		//获取列表
		getlist() {
			if (this.loading || this.isEnd) return
			uni.showLoading()
			this.loading = false
			this.$http({
				url: 'api/Wechat/businessDistrict',
				data: {
					page_index: this.page_index,
					keyword:this.keyword,
					page_size: 10,
					type: this.cateindex == 0 ? 2 : 1,//type 1楼层 2分类
					cate_id:  this.floor,//type=1时传,//type=2时传
					// floor: this.floor,//type=1时传 
				}
			}).then(res => {
				if (res.data.length) {
					this.list.push(...res.data)
					this.page_index++
				}
				this.isEnd = res.data.length < 10
				this.is_data = false
			}).finally(() => {
				uni.hideLoading()
				this.loading = false
			})
		},
		//获取分类列表
		getcate() {
			this.$http({
				url: 'api/Wechat/storeCate',
			}).then(res => {
				this.tiptypelist = res.data
				this.tiptypelist.unshift({ name: '全部', id: 0 });
			})
		},
		//获取楼层
		getfloorlist() {
			this.$http({
				url: 'api/Wechat/buildFloor'
			}).then(res => {
				this.floorlist = res.data
				this.floorlist.unshift('全部');
			})
		},
		tostoredetail(item) {
			uni.navigateTo({
				url: '/pageshop/storeinfo/storeinfo?id=' + item.id
			})
		}
	}
}
</script>

<style>
page {
	background-color: #F7F7F7;
}
</style>
<style lang="scss" scoped>
.business-district {
	display: grid;
	flex-direction: column;
	grid-template-rows: 320rpx calc(100vh - 320rpx);
	height: 100vh;

	.content {
		flex: 1;
		display: flex;

		.cate {
			min-width: 200rpx;
			width: 200rpx;
			box-shadow: 0px 0px 10rpx rgba(0, 0, 0, .1);
			height: 100%;
			background-color: white;

			.cate-item {
				padding: 20rpx;
				text-align: center;
				color: #222222;
			}

			.cate-item-select {
				color: #F94D29;
			}
		}

		.list {
			height: 100%;
			flex: 1;
			display: flex;
			flex-direction: column;
			padding: 0rpx 20rpx;
			gap: 20rpx;

			.list-item {
				background-color: white;
				display: flex;
				align-items: center;
				padding: 20rpx;

				.item-content {
					// flex: 1;
					margin-left: 20rpx;
					.discount_percent{
						display: flex;
						justify-content: flex-end;
						background: linear-gradient(90deg, #F94D29 0%, #F99529 100%);
						padding: 0 15rpx;
						font-size: 23rpx;
						color: #FFF;
						width: fit-content;
						border-radius: 10rpx;
						text-align: right;
						margin: 15rpx 0 0 180rpx;
					}
					// display: flex;
					// flex-direction: column;
					// view:nth-child(2){
					// 	margin-top: 20rpx;
					// 	font-size: 26rpx;
					// 	color: gray;
					// }
				}
			}
		}
	}
}

.header {
	height: 320rpx;
	background: url(https://zdcloud.zxkjnc.com/images/5bfb.png) no-repeat;
	width: 100%;
	background-size: 100% 320rpx;
	position: absolute;
	z-index: 99999999;
}

.navbar {
	.navbar-fixed {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 399;
		width: 100%;
		// height: 102rpx;
		// padding-bottom: 20rpx;
		background: transparent;


		.navbar-content {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 0rpx 30rpx;
			// height: 142rpx;
			box-sizing: border-box;

			image {
				width: 19rpx;
				height: 35rpx;
				margin-right: 20rpx;
			}

			.navbar-search {
				display: flex;
				align-items: center;
				// padding: 0 10px;
				width: 100%;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;

			}

		}
	}
}

.searchbox {
	width: 100%;
	height: 134rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	// margin-top: 40rpx;

	.search {
		width: 690rpx;
		height: 40rpx;
		padding: 15rpx 0;
		background: #FFFFFF;
		border-radius: 36rpx;
		// border: 2rpx solid #F94D29;
		display: flex;
		align-items: center;
		margin: 0 auto;
		justify-content: space-between;

		.scan {
			width: 76rpx;
			text-align: center;
			// border-right: solid 2rpx #F2F2F2;

			image {
				width: 32rpx;
				height: 28rpx;
			}
		}

		.inputbox {
			width: 448rpx;
			height: 40rpx;
			padding: 0 24rpx;

			>input {
				width: 100%;
			}
		}

		.searchbut {
			width: 112rpx;
			height: 62rpx;
			background: linear-gradient(180deg, #F94D29 0%, #F99529 100%);
			border-radius: 36rpx;
			font-size: 28rpx;
			font-family: Source Han Sans CN-Medium, Source Han Sans CN;
			font-weight: 500;
			color: #F7F7F7;
			line-height: 62rpx;
			text-align: center;
			margin-right: 5rpx;
		}
	}
}

.catebox {
	width: 750rpx;
	// height: 298rpx;
	background: #F7F7F7;
	box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(249, 149, 41, 0.2);
	// border-radius: 20rpx 20rpx 0 0;
	position: absolute;
	z-index: 99999999;

	// margin-top: 134rpx;
	.titbox {
		width: 750rpx;
		height: 98rpx;
		display: flex;


		.cateitem {
			width: 50%;
			// text-align: center;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			font-family: Source Han Sans CN-Medium, Source Han Sans CN;
			font-weight: 500;
			color: #222222;

			image {
				width: 14rpx;
				height: 12rpx;
				margin-left: 10rpx;
			}
		}
	}


}

.listbox {
	width: 702rpx;
	margin: 0 26rpx;
	display: flex;
	flex-wrap: wrap;

	.listitem {
		width: 33.3%;
		position: relative;
		margin-bottom: 24rpx;

		.store {
			width: 218rpx;
			height: 355rpx;
			background: linear-gradient(89deg, #F6D38F 0%, #FEF4D0 52%, #F6D38F 100%);
			box-shadow: inset 0rpx 0rpx 4rpx 2rpx #C09667;
			border-radius: 16rpx;
			opacity: 1;
			text-align: center;
			padding-top: 8rpx;
			position: relative;
			margin: 0 auto;

			.storeimg {
				width: 202rpx;
				height: 178rpx;
				background: #FFFFFF;
				box-shadow: inset 0rpx 0rpx 4rpx 2rpx #C09667;
				border-radius: 16rpx;
				opacity: 1;
				border: 2rpx solid #DBBF88;
				margin: 0 auto;

				image {
					width: 202rpx;
					height: 178rpx;
				}
			}

			.logobox {
				width: 86rpx;
				height: 86rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 2rpx 4rpx 2rpx #DEAC69, inset 0rpx 4rpx 8rpx 2rpx #DFB78A;
				opacity: 1;
				z-index: 2;
				border: 2rpx solid #DBBF88;
				margin: -35rpx auto 0 auto;
				border-radius: 100%;
				position: absolute;
				left: 50%;
				transform: translate(-50%, 0);

				image {
					width: 86rpx;
					height: 86rpx;
					border-radius: 100%;
				}
			}

			.address {
				font-size: 30rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #222222;
			}

			.storename {
				font-size: 24rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #311200;
				width: 195rpx;
				margin: 5rpx auto 0 auto;
				-webkit-line-clamp: 2;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}

		.newstore {
			position: absolute;
			width: 82rpx;
			height: 58rpx;
			left: 0;
			top: 10rpx;
		}
	}
}

.tiptype {
	width: 100%;
	padding-top: 450rpx;
	background-color: #FFF;

	.boxitem {
		display: flex;
		flex-wrap: wrap;
		width: 690rpx;
		padding: 40rpx 30rpx;

		.itembox {
			height: 72rpx;
			border-radius: 40rpx;
			border: 2rpx solid #999999;
			line-height: 72rpx;
			width: fit-content;
			padding: 0 50rpx;
			margin-right: 24rpx;
			margin-bottom: 20rpx;
		}
	}
}
</style>
